import routeConfig from '@/router/routerConfig.js'
async function deepAddRoute(children, router) {
        try {
            if (!children) return
            let routeConfigArr = [...routeConfig]
            for (let index = 0; index < children.length; index++) {
                const element = children[index]
                if (element.children && element.children.length > 0) {
                    for (let i = 0; i < element.children.length; i++) {
                        await deepAddRoute(element.children, router)
                    }
                }
                for (let i = 0; i < routeConfigArr.length; i++) {
                    if (element.path == routeConfigArr[i].path) {
                        element.component = routeConfigArr[i].component
                    }
                }
                await router.addRoute(element)
            }
        } catch (error) {
            console.log(error,'error999999999999999')
        }
    }
 
function treeToArray(tree) {
    return tree.reduce((res, item) => {
      const { children, ...i } = item
      return res.concat(i, children && children.length ? treeToArray(children) : [])
    }, [])
  }
  
export {
    deepAddRoute,
    treeToArray
}